package fiszki.namespace;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
 
public class SetTasksAdapter extends ArrayAdapter<SetTasks> {
    private Activity context;
    private List<SetTasks> tasks;
    
    public SetTasksAdapter(Activity context, List<SetTasks> tasks) {
        super(context, R.layout.lv_sets_item, tasks);
        this.context = context;
        this.tasks = tasks;
    }
 
    static class ViewHolder {
        public TextView tvName;
        public TextView tvQuestionLang;
        public TextView tvAnswerLang;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        View rowView = convertView;
        
        if(rowView == null) {
            LayoutInflater layoutInflater = context.getLayoutInflater();
            rowView = layoutInflater.inflate(R.layout.lv_sets_item, null, true);
            viewHolder = new ViewHolder();
            viewHolder.tvName = (TextView) rowView.findViewById(R.id.tvName);
            viewHolder.tvQuestionLang = (TextView) rowView.findViewById(R.id.tvQuestionLang);
            viewHolder.tvAnswerLang = (TextView) rowView.findViewById(R.id.tvAnswerLang);

            rowView.setTag(viewHolder);
        } 
        else {
            viewHolder = (ViewHolder) rowView.getTag();
        }
        
        SetTasks task = tasks.get(position);
        viewHolder.tvName.setText(task.getName());
        viewHolder.tvQuestionLang.setText(task.getQuestionLang());
        viewHolder.tvAnswerLang.setText(task.getAnswerLang());
        
        return rowView;
    }
}